﻿using System;
using UnityEngine;

namespace RootMotion.FinalIK
{
	// Token: 0x02000065 RID: 101
	public class GenericPoser : Poser
	{
		// Token: 0x0600044A RID: 1098 RVA: 0x0002F8D8 File Offset: 0x0002DAD8
		[ContextMenu("Auto-Mapping")]
		public override void AutoMapping()
		{
			if (this.poseRoot == null)
			{
				this.maps = new GenericPoser.Map[0];
				return;
			}
			this.maps = new GenericPoser.Map[0];
			Transform[] componentsInChildren = base.transform.GetComponentsInChildren<Transform>();
			Transform[] componentsInChildren2 = this.poseRoot.GetComponentsInChildren<Transform>();
			for (int i = 1; i < componentsInChildren.Length; i++)
			{
				Transform targetNamed = this.GetTargetNamed(componentsInChildren[i].name, componentsInChildren2);
				if (targetNamed != null)
				{
					Array.Resize<GenericPoser.Map>(ref this.maps, this.maps.Length + 1);
					this.maps[this.maps.Length - 1] = new GenericPoser.Map(componentsInChildren[i], targetNamed);
				}
			}
			this.StoreDefaultState();
		}

		// Token: 0x0600044B RID: 1099 RVA: 0x0002F98C File Offset: 0x0002DB8C
		public override void StoreDefaultState()
		{
			for (int i = 0; i < this.maps.Length; i++)
			{
				this.maps[i].StoreDefaultState();
			}
		}

		// Token: 0x0600044C RID: 1100 RVA: 0x0002F9C0 File Offset: 0x0002DBC0
		public override void FixTransforms()
		{
			for (int i = 0; i < this.maps.Length; i++)
			{
				this.maps[i].FixTransform();
			}
		}

		// Token: 0x0600044D RID: 1101 RVA: 0x0002F9F4 File Offset: 0x0002DBF4
		public Transform GetTargetNamed(string tName, Transform[] array)
		{
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].name == tName)
				{
					return array[i];
				}
			}
			return null;
		}

		// Token: 0x0600044E RID: 1102 RVA: 0x0002FA30 File Offset: 0x0002DC30
		public void LateUpdate()
		{
			if (this.weight <= 0f)
			{
				return;
			}
			if (this.localPositionWeight <= 0f && this.localRotationWeight <= 0f)
			{
				return;
			}
			if (this.poseRoot == null)
			{
				return;
			}
			float localRotationWeight = this.localRotationWeight * this.weight;
			float localPositionWeight = this.localPositionWeight * this.weight;
			for (int i = 0; i < this.maps.Length; i++)
			{
				this.maps[i].Update(localRotationWeight, localPositionWeight);
			}
		}

		// Token: 0x040002E9 RID: 745
		public GenericPoser.Map[] maps;

		// Token: 0x02000066 RID: 102
		[Serializable]
		public class Map
		{
			// Token: 0x0600044F RID: 1103 RVA: 0x00004BB7 File Offset: 0x00002DB7
			public Map(Transform bone, Transform target)
			{
				this.bone = bone;
				this.target = target;
				this.StoreDefaultState();
			}

			// Token: 0x06000450 RID: 1104 RVA: 0x00004BD3 File Offset: 0x00002DD3
			public void StoreDefaultState()
			{
				this.defaultLocalPosition = this.bone.localPosition;
				this.defaultLocalRotation = this.bone.localRotation;
			}

			// Token: 0x06000451 RID: 1105 RVA: 0x00004BF7 File Offset: 0x00002DF7
			public void FixTransform()
			{
				this.bone.localPosition = this.defaultLocalPosition;
				this.bone.localRotation = this.defaultLocalRotation;
			}

			// Token: 0x06000452 RID: 1106 RVA: 0x0002FAC8 File Offset: 0x0002DCC8
			public void Update(float localRotationWeight, float localPositionWeight)
			{
				this.bone.localRotation = Quaternion.Lerp(this.bone.localRotation, this.target.localRotation, localRotationWeight);
				this.bone.localPosition = Vector3.Lerp(this.bone.localPosition, this.target.localPosition, localPositionWeight);
			}

			// Token: 0x040002EA RID: 746
			public Transform bone;

			// Token: 0x040002EB RID: 747
			public Transform target;

			// Token: 0x040002EC RID: 748
			public Vector3 defaultLocalPosition;

			// Token: 0x040002ED RID: 749
			public Quaternion defaultLocalRotation;
		}
	}
}
